package org.jeecg.modules.dashboard.service.impl;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.common.util.LoginUserUtil;
import org.jeecg.modules.dashboard.service.IDashBoard;
import org.jeecg.modules.dashboard.vo.*;
import org.jeecg.modules.qyxx.entity.CsPtQyxx;
import org.jeecg.modules.xxgx.cxtj.param.XxFptjSlParam;
import org.jeecg.modules.xxgx.cxtj.service.ICsXxFptjService;
import org.jeecg.modules.xxgx.cxtj.vo.XxFptjSlDTO;
import org.jeecg.modules.xxgx.cxtj.vo.XxFptjSlMxDTO;
import org.jeecg.modules.xxgx.djgl.entity.CsXxDkdj;
import org.jeecg.modules.xxgx.djgl.entity.CsXxYkdj;
import org.jeecg.modules.xxgx.djgl.service.ICsXxDkdjService;
import org.jeecg.modules.xxgx.djgl.service.ICsXxYkdjService;
import org.jeecg.modules.xxgx.sxed.entity.CsXxSxed;
import org.jeecg.modules.xxgx.sxed.service.ICsXxSxedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

@Service
public class DashBoardImpl implements IDashBoard {

    @Autowired
    private ICsXxSxedService iCsXxSxedService;

    @Autowired
    private ICsXxFptjService fptjService;

    @Autowired
    private ICsXxDkdjService iCsXxDkdjService;

    @Autowired
    private ICsXxYkdjService iCsXxYkdjService;

    @Override
    public Result<CreditVo> queryCredit() {
        CreditVo creditVo = new CreditVo();
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        CsXxSxed csXxSxed = iCsXxSxedService.lambdaQuery().eq(CsXxSxed::getCompanyId, user.getCompanyId()).one();
        if (csXxSxed != null) {
            creditVo.setTotalCredit(Convert.toBigDecimal(csXxSxed.getZsxed(), BigDecimal.ZERO));
            creditVo.setUsedCredit(Convert.toBigDecimal(csXxSxed.getYysxed(), BigDecimal.ZERO));
            creditVo.setRemainingCredit(Convert.toBigDecimal(csXxSxed.getSysxed(), BigDecimal.ZERO));
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            creditVo.setEdgxrq(sdf.format(csXxSxed.getEdgxrq()));
        }
        return Result.OK(creditVo);
    }

    public XxFptjSlDTO getlzfp(String kprq) {
        CsPtQyxx qyxx = LoginUserUtil.getQyxxByLoginUser();
        if(qyxx == null){
            return new XxFptjSlDTO();
        }
        XxFptjSlParam param = new XxFptjSlParam();
        param.setKprq(kprq);
        param.setNsrsbh(qyxx.getNsrsbh());
        param.setFpzt("0");
        List<String> orgcodes = LoginUserUtil.getOrgCodesByLoginUser();
        param.setSysOrgCodeArr(orgcodes);

        return fptjService.getXxFpxxtjHj(param);
    }

    public XxFptjSlDTO getlzfpRange(String kprqq,String kprqz) {
        CsPtQyxx qyxx = LoginUserUtil.getQyxxByLoginUser();
        if(qyxx == null){
            return new XxFptjSlDTO();
        }
        XxFptjSlParam param = new XxFptjSlParam();
        param.setKprqq(kprqq);
        param.setKprqz(kprqz);
        param.setNsrsbh(qyxx.getNsrsbh());
        param.setFpzt("0");
        List<String> orgcodes = LoginUserUtil.getOrgCodesByLoginUser();
        param.setSysOrgCodeArr(orgcodes);
        return fptjService.getXxFpxxtjHj(param);
    }

    @Override
    public Result<LzfpVo> lzfp() {
        LzfpVo lzfpVo = new LzfpVo();
        List<LzfpMxVo> lzfpMxVoList = new ArrayList<>();
        CsPtQyxx qyxx = LoginUserUtil.getQyxxByLoginUser();
        if(qyxx == null){
            return Result.OK(lzfpVo);
        }
        //1 得到近10天的日期
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String now = "";
        String one = "";
        String two = "";
        String three = "";
        String four = "";
        String five = "";
        String six = "";
        String seven = "";
        String eight = "";
        String nine = "";
        Calendar calc = Calendar.getInstance();
        try {
            calc.setTime(new Date());
            calc.add(Calendar.DATE, -9);
            Date minDateOne = calc.getTime();
            one = sdf.format(minDateOne);
            XxFptjSlDTO xxFpxxtjHjOne = getlzfp(one);
            LzfpMxVo lzfpMxVoOne = new LzfpMxVo();
            lzfpMxVoOne.setX(one);
            lzfpMxVoOne.setY(Convert.toBigDecimal(xxFpxxtjHjOne.getHjje(),BigDecimal.ZERO));
            lzfpMxVoList.add(lzfpMxVoOne);

            calc.setTime(new Date());
            calc.add(Calendar.DATE, -8);
            Date minDateTwo = calc.getTime();
            two = sdf.format(minDateTwo);
            XxFptjSlDTO xxFpxxtjHjTwo = getlzfp(two);
            LzfpMxVo lzfpMxVoTwo = new LzfpMxVo();
            lzfpMxVoTwo.setX(two);
            lzfpMxVoTwo.setY(Convert.toBigDecimal(xxFpxxtjHjTwo.getHjje(),BigDecimal.ZERO));
            lzfpMxVoList.add(lzfpMxVoTwo);


            calc.setTime(new Date());
            calc.add(Calendar.DATE, -7);
            Date minDateThree = calc.getTime();
            three = sdf.format(minDateThree);
            XxFptjSlDTO xxFpxxtjHjthree = getlzfp(three);
            LzfpMxVo lzfpMxVoThree = new LzfpMxVo();
            lzfpMxVoThree.setX(three);
            lzfpMxVoThree.setY(Convert.toBigDecimal(xxFpxxtjHjthree.getHjje(),BigDecimal.ZERO));
            lzfpMxVoList.add(lzfpMxVoThree);


            calc.setTime(new Date());
            calc.add(Calendar.DATE, -6);
            Date minDateFour = calc.getTime();
            four = sdf.format(minDateFour);
            XxFptjSlDTO xxFpxxtjHjfour = getlzfp(four);
            LzfpMxVo lzfpMxVoFour = new LzfpMxVo();
            lzfpMxVoFour.setX(four);
            lzfpMxVoFour.setY(Convert.toBigDecimal(xxFpxxtjHjfour.getHjje(),BigDecimal.ZERO));
            lzfpMxVoList.add(lzfpMxVoFour);

            calc.setTime(new Date());
            calc.add(Calendar.DATE, -5);
            Date minDateFive = calc.getTime();
            five = sdf.format(minDateFive);
            XxFptjSlDTO xxFpxxtjHjfive = getlzfp(five);
            LzfpMxVo lzfpMxVoFive = new LzfpMxVo();
            lzfpMxVoFive.setX(five);
            lzfpMxVoFive.setY(Convert.toBigDecimal(xxFpxxtjHjfive.getHjje(),BigDecimal.ZERO));
            lzfpMxVoList.add(lzfpMxVoFive);

            calc.setTime(new Date());
            calc.add(Calendar.DATE, -4);
            Date minDateSix = calc.getTime();
            six = sdf.format(minDateSix);
            XxFptjSlDTO xxFpxxtjHjsix = getlzfp(six);
            LzfpMxVo lzfpMxVoSix = new LzfpMxVo();
            lzfpMxVoSix.setX(six);
            lzfpMxVoSix.setY(Convert.toBigDecimal(xxFpxxtjHjsix.getHjje(),BigDecimal.ZERO));
            lzfpMxVoList.add(lzfpMxVoSix);

            calc.setTime(new Date());
            calc.add(Calendar.DATE, -3);
            Date minDateSeven = calc.getTime();
            seven = sdf.format(minDateSeven);
            XxFptjSlDTO xxFpxxtjHjseven = getlzfp(seven);
            LzfpMxVo lzfpMxVoSeven = new LzfpMxVo();
            lzfpMxVoSeven.setX(seven);
            lzfpMxVoSeven.setY(Convert.toBigDecimal(xxFpxxtjHjseven.getHjje(),BigDecimal.ZERO));
            lzfpMxVoList.add(lzfpMxVoSeven);


            calc.setTime(new Date());
            calc.add(Calendar.DATE, -2);
            Date minDateEight = calc.getTime();
            eight = sdf.format(minDateEight);
            XxFptjSlDTO xxFpxxtjHjeight = getlzfp(eight);
            LzfpMxVo lzfpMxVoEight = new LzfpMxVo();
            lzfpMxVoEight.setX(eight);
            lzfpMxVoEight.setY(Convert.toBigDecimal(xxFpxxtjHjeight.getHjje(),BigDecimal.ZERO));
            lzfpMxVoList.add(lzfpMxVoEight);

            calc.setTime(new Date());
            calc.add(Calendar.DATE, -1);
            Date minDateNine = calc.getTime();
            nine = sdf.format(minDateNine);
            XxFptjSlDTO xxFpxxtjHjnine = getlzfp(nine);
            LzfpMxVo lzfpMxVoNine = new LzfpMxVo();
            lzfpMxVoNine.setX(nine);
            lzfpMxVoNine.setY(Convert.toBigDecimal(xxFpxxtjHjnine.getHjje(),BigDecimal.ZERO));
            lzfpMxVoList.add(lzfpMxVoNine);

            calc.setTime(new Date());
            calc.add(Calendar.DATE, 0);
            Date minDateNow = calc.getTime();
            now = sdf.format(minDateNow);
            XxFptjSlDTO xxFpxxtjHjnow = getlzfp(now);
            LzfpMxVo lzfpMxVoNow = new LzfpMxVo();
            lzfpMxVoNow.setX(now);
            lzfpMxVoNow.setY(Convert.toBigDecimal(xxFpxxtjHjnow.getHjje(),BigDecimal.ZERO));
            lzfpMxVoList.add(lzfpMxVoNow);

            lzfpVo.setLzfplist(lzfpMxVoList);

            XxFptjSlParam paramtotal = new XxFptjSlParam();
            paramtotal.setNsrsbh(qyxx.getNsrsbh());
            paramtotal.setKpyf(now.substring(0, 7));
            paramtotal.setFpzt("0");
            List<String> orgcodes = LoginUserUtil.getOrgCodesByLoginUser();
            paramtotal.setSysOrgCodeArr(orgcodes);
            XxFptjSlDTO xxFpxxtjHjTotal = fptjService.getXxFpxxtjHj(paramtotal);
            lzfpVo.setTotalLzfp(Convert.toBigDecimal(xxFpxxtjHjTotal.getHjje(), BigDecimal.ZERO));

            lzfpVo.setTjyf(now.substring(0, 7));


        } catch (Exception e1) {
            e1.printStackTrace();
        }
        return Result.OK(lzfpVo);
    }

    public BigDecimal gethzfp(String kprq){
        CsPtQyxx qyxx = LoginUserUtil.getQyxxByLoginUser();
        XxFptjSlParam param = new XxFptjSlParam();
        param.setNsrsbh(qyxx.getNsrsbh());
        param.setKprq(kprq);
        List<String> orgcodes = LoginUserUtil.getOrgCodesByLoginUser();
        param.setSysOrgCodeArr(orgcodes);
        List<XxFptjSlMxDTO> xxFpxxtjMx = fptjService.getXxFpxxtjMx(param);
        BigDecimal zfje = xxFpxxtjMx.stream().filter(i -> "0".equals(i.getKplx()) && "2".equals(i.getFpzt())).map(XxFptjSlMxDTO::getBhsje).map(BigDecimal::abs).reduce(BigDecimal.ZERO, BigDecimal::add);
        BigDecimal hcje = xxFpxxtjMx.stream().filter(i -> "1".equals(i.getKplx()) && "1".equals(i.getFpzt())).map(XxFptjSlMxDTO::getBhsje).map(BigDecimal::abs).reduce(BigDecimal.ZERO, BigDecimal::add);
        return zfje.add(hcje);
    }

    public BigDecimal gethzfpRange(String kprqq,String kprqz) {
        CsPtQyxx qyxx = LoginUserUtil.getQyxxByLoginUser();
        XxFptjSlParam param = new XxFptjSlParam();
        param.setKprqq(kprqq);
        param.setKprqz(kprqz);
        param.setNsrsbh(qyxx.getNsrsbh());
        List<String> orgcodes = LoginUserUtil.getOrgCodesByLoginUser();
        param.setSysOrgCodeArr(orgcodes);
        List<XxFptjSlMxDTO> xxFpxxtjMx = fptjService.getXxFpxxtjMx(param);
        BigDecimal zfje = xxFpxxtjMx.stream().filter(i -> "0".equals(i.getKplx()) && "2".equals(i.getFpzt())).map(XxFptjSlMxDTO::getBhsje).map(BigDecimal::abs).reduce(BigDecimal.ZERO, BigDecimal::add);
        BigDecimal hcje = xxFpxxtjMx.stream().filter(i -> "1".equals(i.getKplx()) && "1".equals(i.getFpzt())).map(XxFptjSlMxDTO::getBhsje).map(BigDecimal::abs).reduce(BigDecimal.ZERO, BigDecimal::add);
        return zfje.add(hcje);
    }

    @Override
    public Result<HzfpVo> hzfp() {
        List<HzfpMxVo> hzfpMxVos = new ArrayList<>();
        HzfpVo hzfpVo = new HzfpVo();
        CsPtQyxx qyxx = LoginUserUtil.getQyxxByLoginUser();
        if(qyxx == null){
            return Result.OK(hzfpVo);
        }
        String now = "";
        Calendar calc = Calendar.getInstance();
        calc.setTime(new Date());
        Date datenow = calc.getTime();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        now = sdf.format(datenow);
        XxFptjSlParam param = new XxFptjSlParam();
        param.setNsrsbh(qyxx.getNsrsbh());
        param.setKpyf(now.substring(0, 7));
        List<String> orgcodes = LoginUserUtil.getOrgCodesByLoginUser();
        param.setSysOrgCodeArr(orgcodes);
        List<XxFptjSlMxDTO> xxFpxxtjMx = fptjService.getXxFpxxtjMx(param);
        //作废金额
        BigDecimal zfje = xxFpxxtjMx.stream().filter(i -> "0".equals(i.getKplx()) && "2".equals(i.getFpzt())).map(XxFptjSlMxDTO::getBhsje).reduce(BigDecimal.ZERO, BigDecimal::add);
        //红冲金额
        BigDecimal hcje = xxFpxxtjMx.stream().filter(i -> "1".equals(i.getKplx()) && "1".equals(i.getFpzt())).map(XxFptjSlMxDTO::getBhsje).reduce(BigDecimal.ZERO, BigDecimal::add);
        hzfpVo.setHzfpTotal(zfje.add(hcje));
        hzfpVo.setTjyf(now);

        //计算近10天每天的红字发票
        HzfpMxVo hzfpMxVonow = new HzfpMxVo();
        hzfpMxVonow.setX(now);
        hzfpMxVonow.setY(Convert.toBigDecimal(gethzfp(now),BigDecimal.ZERO));
        hzfpMxVos.add(hzfpMxVonow);

        calc.add(Calendar.DATE, -1);
        Date minDateOne = calc.getTime();
        String one = sdf.format(minDateOne);
        HzfpMxVo hzfpMxVoone = new HzfpMxVo();
        hzfpMxVoone.setX(one);
        hzfpMxVoone.setY(Convert.toBigDecimal(gethzfp(one),BigDecimal.ZERO));
        hzfpMxVos.add(hzfpMxVoone);

        calc.setTime(new Date());
        calc.add(Calendar.DATE, -2);
        Date minDateTwo = calc.getTime();
        String two = sdf.format(minDateTwo);
        HzfpMxVo hzfpMxVotwo = new HzfpMxVo();
        hzfpMxVotwo.setX(two);
        hzfpMxVotwo.setY(Convert.toBigDecimal(gethzfp(two),BigDecimal.ZERO));
        hzfpMxVos.add(hzfpMxVotwo);

        calc.setTime(new Date());
        calc.add(Calendar.DATE, -3);
        Date minDateThree = calc.getTime();
        String three = sdf.format(minDateThree);
        HzfpMxVo hzfpMxVothree = new HzfpMxVo();
        hzfpMxVothree.setX(three);
        hzfpMxVothree.setY(Convert.toBigDecimal(gethzfp(three),BigDecimal.ZERO));
        hzfpMxVos.add(hzfpMxVothree);

        calc.setTime(new Date());
        calc.add(Calendar.DATE, -4);
        Date minDatefour = calc.getTime();
        String four = sdf.format(minDatefour);
        HzfpMxVo hzfpMxVofour = new HzfpMxVo();
        hzfpMxVofour.setX(four);
        hzfpMxVofour.setY(Convert.toBigDecimal(gethzfp(four),BigDecimal.ZERO));
        hzfpMxVos.add(hzfpMxVofour);

        calc.setTime(new Date());
        calc.add(Calendar.DATE, -5);
        Date minDatefive = calc.getTime();
        String five = sdf.format(minDatefive);
        HzfpMxVo hzfpMxVofive = new HzfpMxVo();
        hzfpMxVofive.setX(five);
        hzfpMxVofive.setY(Convert.toBigDecimal(gethzfp(five),BigDecimal.ZERO));
        hzfpMxVos.add(hzfpMxVofive);

        calc.setTime(new Date());
        calc.add(Calendar.DATE, -6);
        Date minDatesix = calc.getTime();
        String six = sdf.format(minDatesix);
        HzfpMxVo hzfpMxVosix = new HzfpMxVo();
        hzfpMxVosix.setX(six);
        hzfpMxVosix.setY(Convert.toBigDecimal(gethzfp(six),BigDecimal.ZERO));
        hzfpMxVos.add(hzfpMxVosix);

        calc.setTime(new Date());
        calc.add(Calendar.DATE, -7);
        Date minDateseven = calc.getTime();
        String seven = sdf.format(minDateseven);
        HzfpMxVo hzfpMxVoseven = new HzfpMxVo();
        hzfpMxVoseven.setX(seven);
        hzfpMxVoseven.setY(Convert.toBigDecimal(gethzfp(seven),BigDecimal.ZERO));
        hzfpMxVos.add(hzfpMxVoseven);

        calc.setTime(new Date());
        calc.add(Calendar.DATE, -8);
        Date minDateeight = calc.getTime();
        String eight = sdf.format(minDateeight);
        HzfpMxVo hzfpMxVoeight = new HzfpMxVo();
        hzfpMxVoeight.setX(eight);
        hzfpMxVoeight.setY(Convert.toBigDecimal(gethzfp(eight),BigDecimal.ZERO));
        hzfpMxVos.add(hzfpMxVoeight);

        calc.setTime(new Date());
        calc.add(Calendar.DATE, -9);
        Date minDatenine = calc.getTime();
        String nine = sdf.format(minDatenine);
        HzfpMxVo hzfpMxVonine = new HzfpMxVo();
        hzfpMxVonine.setX(nine);
        hzfpMxVonine.setY(Convert.toBigDecimal(gethzfp(nine),BigDecimal.ZERO));
        hzfpMxVos.add(hzfpMxVonine);

        hzfpVo.setHzfplist(hzfpMxVos);
        return Result.OK(hzfpVo);
    }

    @Override
    public Result<DkdjVo> dkdj() {
        DkdjVo dkdjVo = new DkdjVo();
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        QueryWrapper<CsXxDkdj> queryWrapper = new QueryWrapper<>();
        DateTime start = DateUtil.beginOfMonth(new Date());
        DateTime end = DateUtil.endOfMonth(new Date());
        queryWrapper.ge("djrq", start);
        queryWrapper.le("djrq", end);
        queryWrapper.eq("company_id", user.getCompanyId());
        queryWrapper.eq("djzt", "0");
        List<String> orgcodes = LoginUserUtil.getOrgCodesByLoginUser();
        queryWrapper.in("sys_org_code",orgcodes);
        long countdkdj = iCsXxDkdjService.count(queryWrapper);

        QueryWrapper<CsXxYkdj> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.ge("djrq", start);
        queryWrapper1.le("djrq", end);
        queryWrapper1.eq("company_id", user.getCompanyId());
        queryWrapper1.in("sys_org_code",orgcodes);
        long countykdj = iCsXxYkdjService.count(queryWrapper1);

        int total = (int) countdkdj + (int) countykdj;

        if(total == 0){
            dkdjVo.setTotalDj(total);
            dkdjVo.setTotalDkdj((int) countdkdj);
            dkdjVo.setTotalYkdj((int) countykdj);

            dkdjVo.setPercent(BigDecimal.ZERO);
            dkdjVo.setPercentStr("0");
            dkdjVo.setPercentBfh("0%");
        }else{
            dkdjVo.setTotalDj(total);
            dkdjVo.setTotalDkdj((int) countdkdj);
            dkdjVo.setTotalYkdj((int) countykdj);

            BigDecimal totalbig = new BigDecimal(total);
            BigDecimal dkbig = new BigDecimal(countdkdj);
            BigDecimal percent = dkbig.divide(totalbig, 2, RoundingMode.HALF_UP);
            if(totalbig.compareTo(dkbig) == 0){
                dkdjVo.setPercent(new BigDecimal("1.00"));
                dkdjVo.setPercentStr("100");
                dkdjVo.setPercentBfh("100%");
            }else{
                dkdjVo.setPercent(percent);
                dkdjVo.setPercentStr(percent.multiply(new BigDecimal(100)).stripTrailingZeros().toString());
                dkdjVo.setPercentBfh(percent.multiply(new BigDecimal(100)).stripTrailingZeros() + "%");
            }

        }
        return Result.OK(dkdjVo);
    }

    @Override
    public Result<FptjVo> fptj(String type) {
        FptjVo fptjVo = new FptjVo();
        //解析type
        String fplx = type.substring(0, 2);
        String time = type.substring(2);
        if ("lz".equals(fplx)) {
            fptjVo = lzpftj(time);
        } else if ("hz".equals(fplx)) {
            fptjVo = hzpftj(time);
        }
        return Result.OK(fptjVo);
    }


    public FptjVo lzpftj(String time) {
        List<FpMxVo> fpMxVoList = new ArrayList<>();
        FptjVo fptjVo = new FptjVo();
        if ("bz".equals(time)) {
            //本周 7天
            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String monday = dateFormat.format(calendar.getTime());
            calendar.add(Calendar.DAY_OF_MONTH, 1);
            String tuesday = dateFormat.format(calendar.getTime());
            calendar.add(Calendar.DAY_OF_MONTH, 1);
            String wensday = dateFormat.format(calendar.getTime());
            calendar.add(Calendar.DAY_OF_MONTH, 1);
            String Thursday = dateFormat.format(calendar.getTime());
            calendar.add(Calendar.DAY_OF_MONTH, 1);
            String Friday = dateFormat.format(calendar.getTime());
            calendar.add(Calendar.DAY_OF_MONTH, 1);
            String Saturday = dateFormat.format(calendar.getTime());
            calendar.add(Calendar.DAY_OF_MONTH, 1);
            String Sunday = dateFormat.format(calendar.getTime());

            XxFptjSlDTO getlzfpmonday = getlzfp(monday);
            FpMxVo fpMxVomonday = new FpMxVo();
            fpMxVomonday.setX(monday);
            fpMxVomonday.setY(Convert.toBigDecimal(getlzfpmonday.getHjje(),BigDecimal.ZERO));
            fpMxVoList.add(fpMxVomonday);

            XxFptjSlDTO getlzfptuesday = getlzfp(tuesday);
            FpMxVo fpMxVotuesday = new FpMxVo();
            fpMxVotuesday.setX(tuesday);
            fpMxVotuesday.setY(Convert.toBigDecimal(getlzfptuesday.getHjje(),BigDecimal.ZERO));
            fpMxVoList.add(fpMxVotuesday);

            XxFptjSlDTO getlzfpwensday = getlzfp(wensday);
            FpMxVo fpMxVowensday = new FpMxVo();
            fpMxVowensday.setX(wensday);
            fpMxVowensday.setY(Convert.toBigDecimal(getlzfpwensday.getHjje(),BigDecimal.ZERO));
            fpMxVoList.add(fpMxVowensday);

            XxFptjSlDTO getlzfpThursday = getlzfp(Thursday);
            FpMxVo fpMxVoThursday = new FpMxVo();
            fpMxVoThursday.setX(Thursday);
            fpMxVoThursday.setY(Convert.toBigDecimal(getlzfpThursday.getHjje(),BigDecimal.ZERO));
            fpMxVoList.add(fpMxVoThursday);

            XxFptjSlDTO getlzfpFriday = getlzfp(Friday);
            FpMxVo fpMxVoFriday = new FpMxVo();
            fpMxVoFriday.setX(Friday);
            fpMxVoFriday.setY(Convert.toBigDecimal(getlzfpFriday.getHjje(),BigDecimal.ZERO));
            fpMxVoList.add(fpMxVoFriday);

            XxFptjSlDTO getlzfpSaturday = getlzfp(Saturday);
            FpMxVo fpMxVoSaturday = new FpMxVo();
            fpMxVoSaturday.setX(Saturday);
            fpMxVoSaturday.setY(Convert.toBigDecimal(getlzfpSaturday.getHjje(),BigDecimal.ZERO));
            fpMxVoList.add(fpMxVoSaturday);

            XxFptjSlDTO getlzfpSunday = getlzfp(Sunday);
            FpMxVo fpMxVoSunday = new FpMxVo();
            fpMxVoSunday.setX(Sunday);
            fpMxVoSunday.setY(Convert.toBigDecimal(getlzfpSunday.getHjje(),BigDecimal.ZERO));
            fpMxVoList.add(fpMxVoSunday);
        } else if ("by".equals(time)) {
            //本月
            Calendar calendar = Calendar.getInstance();
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            // 设置日期为当月的第一天
            calendar.set(Calendar.DAY_OF_MONTH, 1);
            // 获取当前月份的天数
            int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
            // 循环遍历每一天
            for (int day = 1; day <= daysInMonth; day++) {
                // 打印当前日期
                String eveyday = dateFormat.format(calendar.getTime());
                XxFptjSlDTO getlzfp = getlzfp(eveyday);
                FpMxVo fpMxVo = new FpMxVo();
                fpMxVo.setX(eveyday);
                fpMxVo.setY(getlzfp.getHjje());
                fpMxVoList.add(fpMxVo);
                // 增加一天
                calendar.add(Calendar.DAY_OF_MONTH, 1);
            }
        } else {
            //本年
            // 获取当前日期
            Calendar calendar = Calendar.getInstance();
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            // 获取当前年份
            int year = calendar.get(Calendar.YEAR);
            // 遍历12个月份
            for (int month = Calendar.JANUARY; month <= Calendar.DECEMBER; month++) {
                // 设置为当前年份的月份
                calendar.set(year, month, 1);
                String monthString = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, java.util.Locale.getDefault());
                calendar.set(Calendar.DAY_OF_MONTH,1);
                String startmonth = format.format(calendar.getTime());
                calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
                String endmonth = format.format(calendar.getTime());
                XxFptjSlDTO xxFptjSlDTO = getlzfpRange(startmonth, endmonth);
                FpMxVo fpMxVo = new FpMxVo();
                fpMxVo.setX(monthString);
                fpMxVo.setY(Convert.toBigDecimal(xxFptjSlDTO.getHjje(),BigDecimal.ZERO));
                fpMxVoList.add(fpMxVo);
            }
        }
        fptjVo.setFplist(fpMxVoList);
        return fptjVo;
    }

    public FptjVo hzpftj(String time) {
        List<FpMxVo> fpMxVoList = new ArrayList<>();
        FptjVo fptjVo = new FptjVo();
        if("bz".equals(time)){
            //本周 7天
            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String monday = dateFormat.format(calendar.getTime());
            calendar.add(Calendar.DAY_OF_MONTH, 1);
            String tuesday = dateFormat.format(calendar.getTime());
            calendar.add(Calendar.DAY_OF_MONTH, 1);
            String wensday = dateFormat.format(calendar.getTime());
            calendar.add(Calendar.DAY_OF_MONTH, 1);
            String Thursday = dateFormat.format(calendar.getTime());
            calendar.add(Calendar.DAY_OF_MONTH, 1);
            String Friday = dateFormat.format(calendar.getTime());
            calendar.add(Calendar.DAY_OF_MONTH, 1);
            String Saturday = dateFormat.format(calendar.getTime());
            calendar.add(Calendar.DAY_OF_MONTH, 1);
            String Sunday = dateFormat.format(calendar.getTime());

            FpMxVo fpMxVomonday = new FpMxVo();
            fpMxVomonday.setX(monday);
            fpMxVomonday.setY(Convert.toBigDecimal(gethzfp(monday),BigDecimal.ZERO));
            fpMxVoList.add(fpMxVomonday);

            FpMxVo fpMxVotuesday = new FpMxVo();
            fpMxVotuesday.setX(tuesday);
            fpMxVotuesday.setY(Convert.toBigDecimal(gethzfp(tuesday),BigDecimal.ZERO));
            fpMxVoList.add(fpMxVotuesday);

            FpMxVo fpMxVowensday = new FpMxVo();
            fpMxVowensday.setX(wensday);
            fpMxVowensday.setY(Convert.toBigDecimal(gethzfp(wensday),BigDecimal.ZERO));
            fpMxVoList.add(fpMxVowensday);

            FpMxVo fpMxVoThursday = new FpMxVo();
            fpMxVoThursday.setX(Thursday);
            fpMxVoThursday.setY(Convert.toBigDecimal(gethzfp(Thursday),BigDecimal.ZERO));
            fpMxVoList.add(fpMxVoThursday);

            FpMxVo fpMxVoFriday = new FpMxVo();
            fpMxVoFriday.setX(Friday);
            fpMxVoFriday.setY(Convert.toBigDecimal(gethzfp(Friday),BigDecimal.ZERO));
            fpMxVoList.add(fpMxVoFriday);

            FpMxVo fpMxVoSaturday = new FpMxVo();
            fpMxVoSaturday.setX(Saturday);
            fpMxVoSaturday.setY(Convert.toBigDecimal(gethzfp(Saturday),BigDecimal.ZERO));
            fpMxVoList.add(fpMxVoSaturday);

            FpMxVo fpMxVoSunday = new FpMxVo();
            fpMxVoSunday.setX(Sunday);
            fpMxVoSunday.setY(Convert.toBigDecimal(gethzfp(Sunday),BigDecimal.ZERO));
            fpMxVoList.add(fpMxVoSunday);
        }else if("by".equals(time)){
            //本月
            Calendar calendar = Calendar.getInstance();
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            // 设置日期为当月的第一天
            calendar.set(Calendar.DAY_OF_MONTH, 1);
            // 获取当前月份的天数
            int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
            // 循环遍历每一天
            for (int day = 1; day <= daysInMonth; day++) {
                // 打印当前日期
                String eveyday = dateFormat.format(calendar.getTime());
                FpMxVo fpMxVo = new FpMxVo();
                fpMxVo.setX(eveyday);
                fpMxVo.setY(Convert.toBigDecimal(gethzfp(eveyday),BigDecimal.ZERO));
                fpMxVoList.add(fpMxVo);
                // 增加一天
                calendar.add(Calendar.DAY_OF_MONTH, 1);
            }
        }else{
            //本年
            // 获取当前日期
            Calendar calendar = Calendar.getInstance();
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            // 获取当前年份
            int year = calendar.get(Calendar.YEAR);
            // 遍历12个月份
            for (int month = Calendar.JANUARY; month <= Calendar.DECEMBER; month++) {
                // 设置为当前年份的月份
                calendar.set(year, month, 1);
                String monthString = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, java.util.Locale.getDefault());
                calendar.set(Calendar.DAY_OF_MONTH,1);
                String startmonth = format.format(calendar.getTime());
                calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
                String endmonth = format.format(calendar.getTime());
                FpMxVo fpMxVo = new FpMxVo();
                fpMxVo.setX(monthString);
                fpMxVo.setY(Convert.toBigDecimal(gethzfpRange(startmonth, endmonth),BigDecimal.ZERO));
                fpMxVoList.add(fpMxVo);
            }
        }
        fptjVo.setFplist(fpMxVoList);
        return fptjVo;
    }


    public static void main(String[] args) {
        // 获取当前日期
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        // 获取当前年份
        int year = calendar.get(Calendar.YEAR);
        // 遍历12个月份
        for (int month = Calendar.JANUARY; month <= Calendar.DECEMBER; month++) {
            // 设置为当前年份的月份
            calendar.set(year, month, 1);
            String monthString = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, java.util.Locale.getDefault());
            calendar.set(Calendar.DAY_OF_MONTH,1);
            String startmonth = format.format(calendar.getTime());
            calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
            String endmonth = format.format(calendar.getTime());
        }


    }
}
